(:
  A procedure to number all items in a Display file
  It suppresses any previous numbering
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
 <forum>{
  <name>CSCLWorkshop_HongKong</name>,
let $f_author := "author"
let $f_id := "id"
let $f_parent := "parent"
let $f_message := "text"
let $f_title := "title"   
    
let $t := doc($arguments[1])/display
let $authors := fn:distinct-values($t/item/info[@name=$f_author])
let $items := $t/item
for $item at $p in $items
let $author := $item/info[@name=$f_author]/text()
let $parent := $item/info[@name=$f_parent]/text()
return
  <message id="{$item/info[@name=$f_id]/text()}">{
       <header>{
        <datetime>{jj:unix-to-dateTime(xs:integer($item/info[@name="time"]/time/date))}</datetime>,
			  <author id="{fn:index-of($authors,$author)}">{$author}</author>,
			  <subject>{$item/info[@name=$f_title]/text()}</subject>,
			  if ($parent) then <msgref id="{$parent}"/> else ()
			   
        }</header>,
       <body>{
       		$item/info[@name=$f_message]/text()
       }</body>
  }</message>
}</forum>
